package com.yswy.common.utils.dingding;

import com.aliyun.dingtalkoauth2_1_0.models.GetAccessTokenRequest;
import com.aliyun.dingtalkrobot_1_0.Client;
import com.aliyun.dingtalkrobot_1_0.models.OrgGroupSendHeaders;
import com.aliyun.dingtalkrobot_1_0.models.OrgGroupSendRequest;
import com.aliyun.tea.TeaException;
import com.aliyun.teaopenapi.models.Config;
import com.aliyun.teautil.Common;
import com.aliyun.teautil.models.RuntimeOptions;
import lombok.extern.slf4j.Slf4j;
import org.apache.ibatis.javassist.tools.rmi.Sample;

import java.util.Arrays;
import java.util.List;
@Slf4j
public class DingRes {
    /**
     * 使用 Token 初始化账号Client
     * @return Client
     * @throws Exception
     */
    public static Client createClient() throws Exception {
        Config config = new Config();
        config.protocol = "https";
        config.regionId = "central";
        return new Client(config);
    }

//    public static  String getToken(){
//        try {
////            Client client = DingRes.createClient();
////            GetAccessTokenRequest getAccessTokenRequest = new GetAccessTokenRequest()
////                    .setAppKey("dingeqqpkv3xxxxxx")
////                    .setAppSecret("GT-lsu-taDAxxxsTsxxxx");
////            client.getBearerToken(getAccessTokenRequest).getAccessToken();
//
//        } catch (Exception e) {
//            e.printStackTrace();
//        }
//
//    }


    public static void main(String[] args_) throws Exception {

        Client client = DingRes.createClient();
        OrgGroupSendHeaders orgGroupSendHeaders = new OrgGroupSendHeaders();
        orgGroupSendHeaders.xAcsDingtalkAccessToken = "7e1fa2987cacc38223c4891fb7993833";
        OrgGroupSendRequest orgGroupSendRequest = new OrgGroupSendRequest();
        orgGroupSendRequest.setMsgParam("test");
        orgGroupSendRequest.setRobotCode("20620002");
        try {
            client.orgGroupSendWithOptions(orgGroupSendRequest, orgGroupSendHeaders, new RuntimeOptions());
        } catch (TeaException err) {
            if (!Common.empty(err.code) && !Common.empty(err.message)) {
                // err 中含有 code 和 message 属性，可帮助开发定位问题
                log.info(err.message);
            }

        } catch (Exception _err) {
            TeaException err = new TeaException(_err.getMessage(), _err);
            if (!Common.empty(err.code) && !Common.empty(err.message)) {
                // err 中含有 code 和 message 属性，可帮助开发定位问题
                log.info(err.message);
            }

        }
    }
}
